#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int g_val = 100;

int main(){
    pid_t id = fork();
    if(id == 0){
        int cnt = 0;
        while(1){
            printf("I am a child process, pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
            cnt++;
            sleep(1);
            if(cnt == 3){
                g_val = 300;
                printf("change g_val form %d to %d\n", 100, g_val);
            }
        }
    }else{
        while(1){
            printf("I am a father process, pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
        
            sleep(1);
        }
    }
    return 0;
}
